﻿using Abp.Application.Services.Dto;
using Sw.Hospital.HealthExaminationSystem.Application.ItemGroup;
using Sw.Hospital.HealthExaminationSystem.Application.ItemGroup.Dto;
using Sw.Hospital.HealthExaminationSystem.Common.Bases;
using Sw.Hospital.HealthExaminationSystem.Common.Helpers;
using Sw.Hospital.HealthExaminationSystem.Common.UserCache;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Sw.Hospital.HealthExaminationSystem.UserSettings.ItemGroup
{
    public partial class frmXSZK : UserBaseForm
    {
        private IItemGroupAppService itemGroupApp = new ItemGroupAppService();
        public frmXSZK()
        {
            InitializeComponent();
        }

        private void frmXSZK_Load(object sender, EventArgs e)
        {
            var grouplis = DefinedCacheHelper.GetItemGroups();
            searchLookUpEdit2.Properties.DataSource = grouplis;
           
        }

        private void simpleButton4_Click(object sender, EventArgs e)
        {

            SearchGroupZK searchGroup = new SearchGroupZK(); 
                var list = itemGroupApp.getGroupZK(searchGroup);
            if (!string.IsNullOrEmpty(searchLookUpEdit2.EditValue?.ToString()))
            {
                var group = Guid.Parse(searchLookUpEdit2.EditValue.ToString());
                list = list.Where(p=>p.GroupId== group).ToList();
                
            }
            gridControl1.DataSource = list;
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            frmZKBJ frm = new frmZKBJ();
            frm.ShowDialog();
            if (frm.DialogResult == DialogResult.OK)
            {
                SearchGroupZK searchGroup = new SearchGroupZK();
                var list = itemGroupApp.getGroupZK(searchGroup);
                gridControl1.DataSource = list;
            }
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            var dto = gridControl1.GetFocusedRowDto<ShowGroupZKDto>();
            if (dto != null)
            {
                EntityDto<Guid> entity = new EntityDto<Guid>();
                entity.Id = dto.Id;

                itemGroupApp.DelGroupZK(entity);
                SearchGroupZK searchGroup = new SearchGroupZK();
                var list = itemGroupApp.getGroupZK(searchGroup);
                gridControl1.DataSource = list;
            }
        }

        private void simpleButton3_Click(object sender, EventArgs e)
        {

            var dto = gridControl1.GetFocusedRowDto<ShowGroupZKDto>();
            if (dto != null)
            {
                frmZKBJ frm = new frmZKBJ(dto.Id);
                frm.ShowDialog();
                if (frm.DialogResult == DialogResult.OK)
                {

                    SearchGroupZK searchGroup = new SearchGroupZK();
                    var list = itemGroupApp.getGroupZK(searchGroup);
                    gridControl1.DataSource = list;
                }
            }
        }
    }
}
